package tests;

import common.Utils;
import org.openqa.selenium.By;

import java.io.IOException;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 10715
 * Date: 2024-08-27
 * Time: 17:02
 */
public class CancelLogin extends Utils {
    Class<?> targetclass = CancelLogin.class;
    //四个页面
    String listUrl = "http://192.168.47.135:8653/blog_list.html";

    //编辑页
    String editUrl = "http://192.168.47.135:8653/blog_edit.html";
    //更新页
    String updateUrl = "http://192.168.47.135:8653/blog_update.html?id=21";
    //详情页
    String detailUrl = "http://192.168.47.135:8653/blog_detail.html?id=21";
    private static String url = "";

    public CancelLogin() {
        super(url);
    }
    public void CancelListPage() {
        driver.navigate().to(listUrl);
        String methodName = "";
        driver.navigate().refresh();
        driver.findElement(By.cssSelector("body > div.nav > a:nth-child(6)")).click();
        //是否为登录页面
        driver.findElement(By.cssSelector("body > div.container-login > div"));
        //判断是否可以继续访问
        driver.get(listUrl);
        driver.findElement(By.cssSelector("body > div.container-login > div"));
        try {
            methodName = targetclass.getMethod("CancelListPage").getName();
            getScreenShot(targetclass.getName() + "-" + methodName);
        } catch (IOException | NoSuchMethodException e) {
            throw new RuntimeException(e);
        }
    }
    public void CancelDetailPage() {
        driver.navigate().to(detailUrl);
        String methodName = "";
        driver.navigate().refresh();
        driver.findElement(By.cssSelector("body > div.nav > a:nth-child(6)")).click();
        //是否为登录页面
        driver.findElement(By.cssSelector("body > div.container-login > div"));
        //判断是否可继续访问
        driver.get(detailUrl);
        driver.findElement(By.cssSelector("body > div.container-login > div"));
        try {
            methodName = targetclass.getMethod("CancelDetailPage").getName();
            getScreenShot(targetclass.getName() + "-" + methodName);
        } catch (IOException | NoSuchMethodException e) {
            throw new RuntimeException(e);
        }

    }
    public void CancelEditPage() {
        driver.navigate().to(editUrl);
        String methodName = "";
        driver.navigate().refresh();
        assert driver.findElement(By.cssSelector("#title")).getText().equals("");
        //弹出输入不合法，页面不变
        driver.findElement(By.cssSelector("#submit")).click();
        driver.findElement(By.cssSelector("body > div.container-login > div"));
        try {
            methodName = targetclass.getMethod("CancelEditPage").getName();
            getScreenShot(targetclass.getName() + "-" + methodName);
        } catch (IOException | NoSuchMethodException e) {
            throw new RuntimeException(e);
        }

    }
    public void CancelUpdatePage() {
        driver.navigate().to(updateUrl);
        String methodName = "";
        driver.navigate().refresh();
        driver.findElement(By.cssSelector("body > div.nav > a:nth-child(6)")).click();
        //是否为登录页面
        driver.findElement(By.cssSelector("body > div.container-login > div"));
        //判断是否可以继续访问
        driver.get(updateUrl);
        driver.findElement(By.cssSelector("body > div.container-login > div"));
        try {
            methodName = targetclass.getMethod("CancelUpdatePage").getName();
            getScreenShot(targetclass.getName() + "-" + methodName);
        } catch (IOException | NoSuchMethodException e) {
            throw new RuntimeException(e);
        }
    }
}
